package com.justnow.offer;

import java.util.HashMap;
import java.util.Scanner;

/**
 * @author justnow
 * Created on 2020-09-10
 * Description
 *
 * 请实现一个36进制转10进制的函数，不能用语言已有的库函数直接转化，请注意转化出来的
 * 长整形能支持的最大值是：
 * Long.MAX_VALUE 和 Long.MIN_VALUE
 */
public class Zuiyou01 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String str = scanner.nextLine();
        HashMap<Character, Integer> map = new HashMap<>();
        int startNumber = 10;
        char startChar = 'a';
        while (startNumber <= 35) {
            map.put(startChar, startNumber);
            startNumber++;
            startChar++;
        }
        int start = 0;
        char startC = '0';
        while (start <= 9) {
            map.put(startC, start);
            start++;
            startC++;
        }
        boolean isMinus = false;
        if (str.charAt(0) == '-') {
            isMinus = true;
            str = str.substring(1);
        }
        StringBuilder stringBuilder = new StringBuilder(str);
        String reverse = stringBuilder.reverse().toString();
        char[] chars = reverse.toCharArray();
        int length = chars.length;
        long result = 0l;
        for (int i = 0; i < length; i++) {
            if (!map.containsKey(chars[i])) {
                System.out.println(0);
                return;
            }
            Integer integer = map.get(chars[i]);
            try {
                result += integer * Math.pow(36, i);
            } catch (Exception e) {
                if (isMinus) {
                    System.out.println(Long.MIN_VALUE);
                    return;
                } else {
                    System.out.println(Long.MAX_VALUE);
                    return;
                }
            }
        }
        if (isMinus) {
            System.out.println(-1 * result);
        } else {
            System.out.println(result);
        }

        //4561031516192243711
        //9223372036854775807
    }
}
